home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
C++
/
Applications
/
nanoInstall 1.0
/
source
/
readThem.cp
< prev
next >
Wrap
Text File
|
1996-07-05
|
2KB
|
83 lines
#include "nanoInstall.h"
void UnlockAddLockRelease( Handle theResource, OSType theType, short resNo);
OSErr GetForkAndClose( short theFork, OSType theType, short resNo);
OSErr readThem()
{
OSErr result = -1; // user canceled
standardgetfile sf;
short resNo = 128;
while( sf.doIt())
{
short resFork = 0;
//
// store resource fork:
//
if( (result = FSpOpenRF( &sf.sfFile, fsCurPerm, &resFork)) == noErr)
{
result = GetForkAndClose( resFork, 'RsFk', resNo);
}
//
// store data fork:
//
short dataFork = 0;
if( (result = FSpOpenDF( &sf.sfFile, fsCurPerm, &dataFork)) == noErr)
{
result = GetForkAndClose( dataFork, 'DtFk', resNo);
}
//
// store finder info:
//
Handle theResource = NewHandle( sizeof( FInfo));
(void)FSpGetFInfo( &sf.sfFile, (FInfo *)*theResource);
UnlockAddLockRelease( theResource, 'fInf', resNo);
//
// store file name:
//
const int length_plus_one = sf.sfFile.name[ 0] + 1;
Handle nameResource = NewHandle( length_plus_one);
BlockMoveData( &sf.sfFile.name, *nameResource, length_plus_one);
UnlockAddLockRelease( nameResource, 'fNam', resNo);
resNo += 1;
}
return result;
}
void UnlockAddLockRelease( Handle theResource, OSType theType, short resNo)
{
// Unlock( theResource); not needed; we release the memory real soon now.
AddResource( theResource, theType, resNo, emptyPString);
SetResAttrs( theResource, resLocked);
ChangedResource( theResource);
ReleaseResource( theResource);
}
OSErr GetForkAndClose( short theFork, OSType theType, short resNo)
{
long numtoread = 0;
(void)GetEOF( theFork, &numtoread);
Handle theResource = NewHandle( numtoread);
OSErr result = FSRead( theFork, &numtoread, *theResource);
FSClose( theFork);
UnlockAddLockRelease( theResource, theType, resNo);
return result;
}